package com.qfedu.controller;

import com.github.pagehelper.PageInfo;
import com.qfedu.entity.Usergroup;
import com.qfedu.service.UsergroupService;
import com.qfedu.util.PageHelperUtil;
import com.qfedu.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * projectName: logistics
 * author: CGY
 * time: 2020/10/9 20:52
 * description:用户组类
 */
@RestController
@RequestMapping("/usergroup")
public class UserGroupController {
    @Autowired
    private UsergroupService usergroupService;

    @RequestMapping("/selectAllUserGroup.do")
    public Result selectAllUserFroup(){
        Result ret = usergroupService.selectAll();
        return ret;
    }

    @RequestMapping("/selectAllGroup.do")
    public PageHelperUtil selectAllGroup(){
        PageInfo pageInfo = usergroupService.selectAllGroup();
        return PageHelperUtil.success(pageInfo.getTotal(),pageInfo.getList());
    }

    @RequestMapping("/addGroup.do")
    public Result addGroup(Usergroup usergroup){
        return usergroupService.addGroup(usergroup);
    }

    @RequestMapping("/selectGroupById.do")
    public Result selectGroupById(Integer groupId){
        return usergroupService.selectGroupById(groupId);
    }

    @RequestMapping("/updateDescription.do")
    public Result updateDescription(Usergroup usergroup){

        return usergroupService.updateDescription(usergroup);
    }

    @RequestMapping("/deleteGroup.do")
    public Result deleteGroup(Long id){
        return usergroupService.deleteGroup(id);
    }

    @RequestMapping("/selectAllFunction.do")
    public Result selectAllFunction(){
        return usergroupService.selectAllFunction();
    }

    @RequestMapping("/selectFunctionByGroup.do")
    public Result selectFunctionByGroup(Long groupId){
        return usergroupService.selectFunctionByGroup(groupId);
    }


    @RequestMapping("/addNewFunc.do")
    public Result addNewFunc(Long groupId, @RequestParam("array[]") Integer[] array){
        return usergroupService.addNewFunc(groupId,array);

    }
}
